package com.ruoyi.web.controller.insect.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.insect.domain.DiseaseRecord;
import com.ruoyi.insect.service.IDiseaseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 历史记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-31
 */
@RestController
@RequestMapping("/insect/record")
public class DiseaseRecordController extends BaseController
{
    @Autowired
    private IDiseaseRecordService diseaseRecordService;

    /**
     * 查询历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('insect:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(DiseaseRecord diseaseRecord)
    {
        startPage();
        List<DiseaseRecord> list = diseaseRecordService.selectDiseaseRecordList(diseaseRecord);
        return getDataTable(list);
    }

    /**
     * 导出历史记录列表
     */
    @PreAuthorize("@ss.hasPermi('insect:record:export')")
    @Log(title = "历史记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DiseaseRecord diseaseRecord)
    {
        List<DiseaseRecord> list = diseaseRecordService.selectDiseaseRecordList(diseaseRecord);
        ExcelUtil<DiseaseRecord> util = new ExcelUtil<DiseaseRecord>(DiseaseRecord.class);
        util.exportExcel(response, list, "历史记录数据");
    }

    /**
     * 获取历史记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('insect:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(diseaseRecordService.selectDiseaseRecordById(id));
    }

    /**
     * 新增历史记录
     */
    @PreAuthorize("@ss.hasPermi('insect:record:add')")
    @Log(title = "历史记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody DiseaseRecord diseaseRecord)
    {
        return toAjax(diseaseRecordService.insertDiseaseRecord(diseaseRecord));
    }

    /**
     * 修改历史记录
     */
    @PreAuthorize("@ss.hasPermi('insect:record:edit')")
    @Log(title = "历史记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DiseaseRecord diseaseRecord)
    {
        return toAjax(diseaseRecordService.updateDiseaseRecord(diseaseRecord));
    }

    /**
     * 删除历史记录
     */
    @PreAuthorize("@ss.hasPermi('insect:record:remove')")
    @Log(title = "历史记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(diseaseRecordService.deleteDiseaseRecordByIds(ids));
    }
}
